<?php

namespace app\api\controller\web\frontend;
use app\common\controller\Api;
use think\facade\Db;

/**
 * 咨询
 */
class Consult extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function add()
    {
        $data = input();

        // 验证
        try {
            $this->validate($data, "Web.consult");
        } catch (\Exception $e) {
            // 验证失败 输出错误信息
            $this->error($e->getMessage());
        }

        // 数据处理
        $data['createtime'] = time();
        $data['updatetime'] = time();
        $data['remark'] = htmlspecialchars($data['remark']);

        $res = Db::name('web_consult')->insert($data);

        if ($res) {
            $this->success('咨询成功，请注意接听回电');
        }else{
            $this->error('咨询失败', 0);
        }
    }



    /**
     * 通用的列表
     */
    public function get_consult_type()
    {
        $type = input('type') ?? 1;
        $where = [];
        if ($type) {
            $where[] = ['type','=',$type];
        }

        $data = Db::name('web_consult_type')
                ->field('id,name,tpic_image,content')
                ->where($where)
                ->where('is_showswitch',1)
                ->where('deletetime','=',null)
                ->order('weigh desc')
                ->select()->toArray();

        $this->success('success', $data);
    }



}
